import heapq

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
ans = 0
cnt = 0
heap = []
for i in range(n):
    heapq.heappush(heap, B[i])
    while heap and A[i] > heap[0]:
        cnt += 1
        heapq.heappop(heap)
    ans += cnt
print(ans)
